package com.cyk.comicforumjava.demos.web;

import com.cyk.comicforumjava.demos.base.ResponseResult;
import com.cyk.comicforumjava.demos.dto.UserDto;
import com.cyk.comicforumjava.demos.enits.Comment;
import com.cyk.comicforumjava.demos.enits.Post;
import com.cyk.comicforumjava.demos.enits.Support;
import com.cyk.comicforumjava.demos.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/posts")
public class PostController {
    @Autowired
    private PostService postService;
   @GetMapping("/getPost/{postId}")
    public ResponseResult getPost(@RequestHeader("token")String token,@PathVariable String postId) throws Exception {
      ResponseResult result= postService.getPost(token,postId);
       return result;
   }
   @PostMapping("/support")
    public ResponseResult support(@RequestBody Support support) throws Exception {
      ResponseResult result= postService.support(support);
       return result;
   }
   @PostMapping("/delSupport")
    public ResponseResult delSupport(@RequestBody Support support) throws Exception {
      ResponseResult result= postService.delSupport(support);
       return result;
   }
   @PostMapping("/comment")
    public ResponseResult comment(@RequestBody Comment comment){
       ResponseResult result= postService.comment(comment);
       return result;
   }
   @PostMapping("/backPost")
    public ResponseResult PostBack(@RequestBody Post post){
       ResponseResult result= postService.backPost(post);
       return result;
   }
   @GetMapping("backPostList/{postId}")
       public ResponseResult backPostList(@PathVariable String postId){
           ResponseResult result= postService.backPostList(postId);
           return result;
   }
   @PostMapping("/getUserPostList")
    public ResponseResult getUserPostList(@RequestBody UserDto userDto){
       ResponseResult result= postService.getUserPostList(userDto);
       return result;
   }

}
